from AStock.ASUtil import LRUCache
from AStock.ASSetting import cache_path
import os
import unittest


class TestLRUCache(unittest.TestCase):

    def testLRUCache(self):
        cache = LRUCache(max_size=5, save_file=os.path.join(cache_path, 'test_cache.dat'))
        cache.load()
        for i in range(6):
            cache.set('test' + str(i), 'aaa' + str(i))

        self.assertEqual(len(cache.linked_map), 5)

        cache.save()

        cache.clear()

        self.assertEqual(len(cache.linked_map), 0)

        cache.load()

        self.assertEqual(len(cache.linked_map), 5)

        print(cache.linked_map)

        self.assertEqual(cache.get('test2'), 'aaa2')

        print(cache.linked_map)
